using System;
using System.Data;
using System.Collections;
using CE.Database;
/// <summary>
/// Summary description for UserProfileDB
/// </summary>
/// 
namespace CE.Provider
{
    public class ProviderWorkShopDB
    {
        public ProviderWorkShopDB()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public Int64 Insert(ProviderWorkShop providerworkshop)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderWorkShopInsertUpdateSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@WorkShopId", providerworkshop.WorkShopId);
            _sPara.Add("@ProviderCompanyId", providerworkshop.ProviderCompanyId);
            _sPara.Add("@WSName", providerworkshop.WSName);
            _sPara.Add("@BlockNo", providerworkshop.BlockNo);
            _sPara.Add("@AreaName", providerworkshop.AreaName);
            _sPara.Add("@BuildingName", providerworkshop.BuildingName);
            _sPara.Add("@LevelNo", providerworkshop.LevelNo);
            _sPara.Add("@RoomNo", providerworkshop.RoomNo);
            _sPara.Add("@StreetName", providerworkshop.StreetName);
            _sPara.Add("@PostCode", providerworkshop.PostCode);
            _sPara.Add("@ZoneName", providerworkshop.ZoneName);
            _sPara.Add("@Country", providerworkshop.Country);
            _sPara.Add("@RefCEUserId", providerworkshop.RefCEUserId);
            _sPara.Add("@Status", providerworkshop.Status);
            _sPara.Add("@Info1", providerworkshop.Info1);
            _sPara.Add("@Info2", providerworkshop.Info2);
            _sPara.Add("@Info3", providerworkshop.Info3);
            _sPara.Add("@Info4", providerworkshop.Info4);
            _sPara.Add("@Info5", providerworkshop.Info5);
            _sPara.Add("@Info6", providerworkshop.Info6);
            _sPara.Add("@Info7", providerworkshop.Info7);
            _sPara.Add("@Info8", providerworkshop.Info8);
            _sPara.Add("@Info9", providerworkshop.Info9);
            _sPara.Add("@Info10", providerworkshop.Info10);

            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result;
        }

        public ProviderWorkShopList GetProviderWorkShopList(Int64 ProviderCompanyId)
        {
            ProviderWorkShopList _providerworkshoplist = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderWorkShopSelectItemList";

            SortedList _spara = new SortedList();
            _spara.Add("@ProviderCompanyId", ProviderCompanyId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _providerworkshoplist = new ProviderWorkShopList();
                    for (int i = 0; i < _dt.Rows.Count; i++)
                    {
                        ProviderWorkShop _workshop = new ProviderWorkShop();
                        _workshop = FillDataRecord(_dt, i);
                        _providerworkshoplist.Add(_workshop);
                    }
                }
            }
            return _providerworkshoplist;
        }

        public ProviderWorkShop GetProviderWorkShop(Int64 ProviderWorkShopId)
        {
            ProviderWorkShop _workshop = null;
            MyDatabase _db = new MyDatabase();
            string _spName = "sprocProviderWorkShopSelectSingleItem";

            SortedList _spara = new SortedList();
            _spara.Add("@WorkShopId", ProviderWorkShopId);

            using (DataTable _dt = _db.GetDataTableBySP(_spName, _spara))
            {
                if (_dt != null && _dt.Rows.Count > 0)
                {
                    _workshop = new ProviderWorkShop();
                    _workshop = FillDataRecord(_dt, 0);
                }
            }
            return _workshop;
        }

        private ProviderWorkShop FillDataRecord(DataTable myDataTable, int RowId)
        {
            ProviderWorkShop myWorkShop = new ProviderWorkShop();
            myWorkShop.WorkShopId = Convert.ToInt64(myDataTable.Rows[RowId]["WorkShopId"].ToString());
            myWorkShop.ProviderCompanyId = Convert.ToInt64(myDataTable.Rows[RowId]["ProviderCompanyId"].ToString());
            myWorkShop.WSName = myDataTable.Rows[RowId]["WSName"].ToString();
            myWorkShop.BlockNo = myDataTable.Rows[RowId]["BlockNo"].ToString();
            myWorkShop.AreaName = myDataTable.Rows[RowId]["AreaName"].ToString();
            myWorkShop.BuildingName = myDataTable.Rows[RowId]["BuildingName"].ToString();
            myWorkShop.LevelNo = myDataTable.Rows[RowId]["LevelNo"].ToString();
            myWorkShop.RoomNo = myDataTable.Rows[RowId]["RoomNo"].ToString();
            myWorkShop.StreetName = myDataTable.Rows[RowId]["StreetName"].ToString();
            myWorkShop.PostCode = myDataTable.Rows[RowId]["PostCode"].ToString();
            myWorkShop.ZoneName = myDataTable.Rows[RowId]["ZoneName"].ToString();
            myWorkShop.Country = myDataTable.Rows[RowId]["Country"].ToString();
            myWorkShop.RefCEUserId = Convert.ToInt64(myDataTable.Rows[RowId]["RefCEUserId"].ToString());
            myWorkShop.Status = Convert.ToBoolean(myDataTable.Rows[RowId]["Status"].ToString());
            myWorkShop.Info1 = myDataTable.Rows[RowId]["Info1"].ToString();
            return myWorkShop;
        }

        public bool Update()
        {
            return true;
        }

        public bool Delete()
        {
            return true;
        }

        public bool Delete(Int64 ProviderWorkShopId, Int64 ProviderCompanyId)
        {
            MyDatabase _db = new MyDatabase();
            Int64 _result = -1;
            string _spName = "[sprocProviderWorkShopDeleteSingleItem]";

            SortedList _sPara = new SortedList();

            #region Parameter
            _sPara.Add("@WorkShopId", ProviderWorkShopId);
            _sPara.Add("@ProviderCompanyId", ProviderCompanyId);
            #endregion

            _result = _db.ExecuteSP(_spName, _sPara);

            return _result > 0;
        }

    }
}